package tcp

import (
	"net"
)

type Client struct {
	*sessionHub
}

func NewClient(initializer func(pipe Pipeline)) *Client {
	return &Client{
		sessionHub: NewSessionHub(initializer),
	}
}

func (c *Client) Connect(addr string) error {
	remoteAddr, err := net.ResolveTCPAddr("tcp", addr)

	if err != nil {
		return err
	}

	tcpConn, err := net.DialTCP("tcp", nil, remoteAddr)

	if err != nil {
		return err
	}

	c.GetSession(*tcpConn).Read()
	return nil
}
